<%@ page language="java" import="java.util.*" import="java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%@ page import="com.bluesky.light.user.*" %>
<%@ page import="com.bluesky.light.healthnews.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	// check if the user is login
	User u = (User)session.getAttribute("user");
	if (u == null) {
		response.sendRedirect("index.jsp");
	}
	
	String name = u.getName();
	HealthNews lastNews = HealthNewsService.getInstance().getLastNews();
	Date lastUpdateTime = null;
	
	if (lastNews == null) {
		HealthNewsService.getInstance().update();
	} else {
		lastUpdateTime = lastNews.getUpdateTime();
		if ((new Date().getTime() - lastUpdateTime.getTime()) > 4320000) {
			HealthNewsService.getInstance().update();
		}
	}
	List<HealthNews> newses = HealthNewsService.getInstance().getNewses();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>light - home</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="css/main.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="css/styles.css">

  </head>
  
  <body>
	<!-- header -->
	<div id="header">
		<div id="logo"><img src="images/logo_small2.png"/></div>
	</div>
	<!-- // header -->
	<!-- nav -->
	<div id="nav">
	</div>
	<!-- // nav -->
	<!-- container -->
	<div id="container">
		<!-- contents -->
		<div id="contents">
	    	<div id="menu">
	    		<div>
	        		<div id="user_info">
	            		<img src="develop/user_icon.jpg"/> 
	            		<b>User</b>
	           		</div>
	           		<div>
	           		<%=name%>
	           		</div>
	            </div>
	            <div>
	            	<%SimpleDateFormat sdf = new SimpleDateFormat("EEE, yyyy-MM-dd", new Locale("US"));%><%=sdf.format(new Date())%><br></br>
	            </div>
	        	<ul>
	            	<li><a href="home.jsp"><img src="images/news.png" /> Health News</a></li>
	                <li><a href="user_subscribe.jsp"><img src="images/surscribe.png" /> Appointment</a></li>
	                <li><a href="user_history.jsp"><img src="images/account.png" /> Health History</a></li>
	                <li><a href="user_hospitalSearchOnMap.jsp"><img src="images/photo.png" /> Searching Hospital</a></li>
	                <li><a href="user_bodyCheckResult.jsp"><img src="images/surscribe.png" /> Body Check Result</a></li>	          
	                <li><a href="user_infoModifyInput.jsp"><img src="images/account.png" /> Account Management</a></li>
	                <li><a href="index.jsp"><img src="images/account.png" /> Logout</a></li>
	            </ul>
	        </div>
	        <div id="main-cont">
	        	<div class="newstable">
				<table>
					<caption><h2>Health News</h2></caption>
					<%
						for (int i = 0; i < newses.size(); i++) {
							HealthNews hn = newses.get(i);
					%>
					<tr>
					<td><a href="<%=hn.getUrl()%>" target="_blank"><%=hn.getTitle()%></a></td>
					</tr>
					<tr>
					<td><%=hn.getContent()%></td>
					</tr>
					<tr><td></td></tr>
					<%
						}
					%>
					<tr><th></th></tr>
					<tr>
					<th>The news provided by <a href="http://www.cn.wsj.com/gb/index.asp">The Wall Street Journal</a></th>
					</tr>
				</table>
				</div>
	        </div>
	    </div>
	    <!-- // contents -->
	</div>
	<!-- // container -->
	<div id="footer">
		<div id="bs_stdio">
	    	©2011-2011 www.bluesky.com.mo All Rights Reserved<br/>
	    	<img src="images/bluesky_logo.png" />
	    </div>
	</div>
  </body>
</html>
